import 'package:flutter/material.dart';
import 'package:wkweb/view/statelessviews.dart';

class StateLayout extends StatelessWidget {
  static const int stateSuccess = 0;
  static const int stateLoading = 1;
  static const int stateError = 2;

  final int state;
  final Widget successWidget;
  final Widget? loadingWidget;
  final Widget? errorWidget;

  const StateLayout(
      {required this.successWidget,
      required this.state,
      this.loadingWidget,
      this.errorWidget,
      Key? key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    switch (state) {
      case stateLoading:
        {
          return loadingWidget ?? DefaultLoadingPage();
        }
      case stateError:
        {
          return errorWidget ?? DefaultErrorPage();
        }
      case stateSuccess:
        {
          return successWidget;
        }
    }
    return Text("请设置成功布局，或传入正确状态");
  }
}
